Skip to main content

Lab 11: Create Alarm Using Terraform

The Nautilus DevOps team is setting up monitoring in their AWS account. As part of this, they need to create a CloudWatch alarm.

Using Terraform, perform the following:

REQUIREMENTS

  1. Create a CloudWatch alarm named devops-alarm.

  2. The alarm should monitor CPU utilization of an EC2 instance.

  3. Trigger the alarm when CPU utilization exceeds 80%.

  4. Set the evaluation period to 5 minutes.

  5. Use a single evaluation period.

    The Terraform working directory is /home/bob/terraform. Create the main.tf file (do not create a different .tf file) to provision the instance.

Note: Right-click under the EXPLORER section in VS Code and select Open in Integrated Terminal to launch the terminal.

Create main.tf

resource "aws_cloudwatch_metric_alarm" "devops-alarm" {
alarm_name = "devops-alarm"
comparison_operator = "GreaterThanThreshold"
evaluation_periods = 1
period = 300
metric_name = "CPUUtilization"
namespace = "AWS/EC2"
statistic = "Average"
threshold = 80
}
terraform init
terraform plan -out kke.plan && terraform apply kke.plan
# or apply forcefully without creating plan and applying it
terraform apply -auto-approve


aws cloudwatch describe-alarms --alarm-names devops